package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysJudgeDetailQuery;
import net.learn.system.query.SysJudgeQuery;
import net.learn.system.service.SysJudgeDetailService;
import net.learn.system.vo.SysCheckBoxDetailVO;
import net.learn.system.vo.SysJudgeDetailVO;
import net.learn.system.vo.SysJudgeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 判断管理
 */
@RestController
@RequestMapping("sys/judgedetail")
@Tag(name="判断管理")
@AllArgsConstructor
public class SysJudgeDetailController {
    @Autowired
    private final SysJudgeDetailService judgeDetailService;
    @GetMapping("getJudgeDetail")
    @Operation(summary = "分页获取判断题详情列表")
    public Result<PageResult<SysJudgeDetailVO>> getJudgeDetail(@Valid SysJudgeDetailQuery query){
        PageResult<SysJudgeDetailVO> page = judgeDetailService.qryJudgeDetailListPage(query);

        return Result.ok(page);
    }
    @PostMapping("getJudgeDetailList")
    @Operation(summary = "获取判断题详情列表")
    public Result<List<SysJudgeDetailVO>> getJudgeDetailList(@RequestBody SysJudgeQuery query){
        List<SysJudgeDetailVO> list = judgeDetailService.getJudgeDetailArray();

        return Result.ok(list);
    }
    @PostMapping("getJudgeDetailList")
    @Operation(summary = "获取试卷题库列表")
    public Result<List<SysJudgeDetailVO>> getPaperJudgeList(@RequestBody SysJudgeDetailQuery query){
        List<SysJudgeDetailVO> list = judgeDetailService.qryPaperJudgeList(query);

        return Result.ok(list);
    }
    @PostMapping("getPaperJudgeCondition")
    @Operation(summary = "获取正在考试试卷题库列表")
    public Result<List<SysJudgeDetailVO>> getPaperJudgeCondition(@RequestBody SysJudgeDetailQuery query){
        List<SysJudgeDetailVO> list = judgeDetailService.qryPaperJudgeCondition(query);

        return Result.ok(list);
    }
    @PostMapping("/updateJudgeDetail")
    @Operation(summary = "修改判断题详情")
    public Result<String> updateJudgeDetail(@RequestBody @Valid SysJudgeDetailVO vo){
        judgeDetailService.updateJudgeDetail(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增判断题详情")
    public Result<String> addJudgeDetail(@RequestBody List<SysJudgeDetailVO> volist){
        for (SysJudgeDetailVO vo:volist){

            judgeDetailService.addJudgeDetail(vo);
        }

        return Result.ok();
    }
    @DeleteMapping
    @Operation(summary = "删除判断题详情")
    public Result<String> deleteById(@RequestBody List<Long> idList){
        judgeDetailService.delete(idList);
        return Result.ok();
    }
}

